#include "mainwin.hpp"

using namespace Gtk;
using namespace Glib;
using namespace sigc;
using namespace std;
using namespace Gnome;

void MainWin::Init()
{
     refXml=Glade::Xml::create("storwords.glade");
     refXml->get_widget("mainwin",mainwin);
     refXml->get_widget("mnuQuit",mnuQuit);
     refXml->get_widget("mnuRefresh",mnuRefresh);
     refXml->get_widget("mnuSave",mnuSave);
     refXml->get_widget("mnuPrefs",mnuPrefs);
     refXml->get_widget("mnuAbout",mnuAbout);
     refXml->get_widget("tbtnRefresh",tbtnRefresh);
     refXml->get_widget("tbtnSaveAs",tbtnSaveAs);
     refXml->get_widget("tbtnPrefs",tbtnPrefs);
     refXml->get_widget("trvSites",trvSites);
     refXml->get_widget("btnAddSite",btnAddSite);
     refXml->get_widget("btnRemoveSite",btnRemoveSite);
     refXml->get_widget("entName",entName);
     refXml->get_widget("entUrl",entUrl);
     refXml->get_widget("entUser",entUser);
     refXml->get_widget("btnEditPass",btnEditPass);
     refXml->get_widget("btnCopyPass",btnCopyPass);
     refXml->get_widget("txtNotes",txtNotes);
     refXml->get_widget("btnSave",btnSave);
     refXml->get_widget("btnRevert",btnRevert);
     
     mnuPrefs->signal_activate().connect(mem_fun(this,&MainWin::tbtnPrefs_Click));
     mnuRefresh->signal_activate().connect(mem_fun(this,&MainWin::tbtnRefresh_Click));
     mnuSave->signal_activate().connect(mem_fun(this,&MainWin::tbtnSaveAs_Click));
     mnuQuit->signal_activate().connect(mem_fun(this,&MainWin::mnuQuit_Click));
     mnuAbout->signal_activate().connect(mem_fun(this,&MainWin::mnuAbout_Click));
     tbtnRefresh->signal_clicked().connect(mem_fun(this,&MainWin::tbtnRefresh_Click));
     tbtnSaveAs->signal_clicked().connect(mem_fun(this,&MainWin::tbtnSaveAs_Click));
     tbtnPrefs->signal_clicked().connect(mem_fun(this,&MainWin::tbtnPrefs_Click));
     trvSites->signal_row_activated().connect(mem_fun(this,&MainWin::trvSites_Row_Activate));
     btnEditPass->signal_clicked().connect(mem_fun(this,&MainWin::btnEditPass_Click));
     btnCopyPass->signal_clicked().connect(mem_fun(this,&MainWin::btnCopyPass_Click));
     btnSave->signal_clicked().connect(mem_fun(this,&MainWin::btnSave_Click));
     btnRevert->signal_clicked().connect(mem_fun(this,&MainWin::btnRevert_Click));
}

MainWin::MainWin()
{
     Init();
}

void MainWin::tbtnRefresh_Click(){}

void MainWin::tbtnSaveAs_Click(){}

void MainWin::tbtnPrefs_Click(){
     ConfigWin().Run(mainwin);
}

void MainWin::trvSites_Row_Activate(const TreeModel::Path& path, TreeViewColumn* column){}

void MainWin::btnEditPass_Click(){}

void MainWin::btnCopyPass_Click(){}

void MainWin::btnSave_Click(){}

void MainWin::btnRevert_Click(){}

void MainWin::mnuQuit_Click(){
    Main::quit();
}

void MainWin::mnuAbout_Click(){
    AboutDialog *about;
    refXml->get_widget("aboutdialog",about);
    about->set_version(VersionString);
    about->signal_response().connect(mem_fun(this, &MainWin::aboutdialog_Dismiss));
    about->set_transient_for(*mainwin);
    about->set_position(WIN_POS_CENTER_ON_PARENT);
    about->present();
}

void MainWin::aboutdialog_Dismiss(int q){
    AboutDialog *about;
    refXml->get_widget("aboutdialog",about);
    about->hide();
}

void MainWin::Run(){
     mainwin->property_visible().set_value(true);
     Main::run(*mainwin);
}
